﻿using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaLibModel.Business;
using YiMeiJiaLibModel.Business.Dto;
using YiMeiJiaLibModel.Config;
using YiMeiJiaLibModel.Enums;
using YiMeiJiaService.Assembly;
using YiMeiJiaService.IService;

namespace YiMeiJiaApp.Pages.Home.Mall
{
    public partial class List
    {
        #region 服务组件

        [Inject] private IAcccount _account { get; set; }
        [Inject] private IGoods _goods { get; set; }

        [Inject] protected NavigationManager Navigation { get; set; }


        [Inject] protected IJSRuntime JSRuntime { get; set; }
        #endregion

        

        #region 绑定数据
        public CoreCmsGoodsCategoryDto _goodsCategory { get; set; }  
        /// <summary>
        /// 搜索的内容
        /// </summary>
        public string searchStr { get; set;  }
        /// <summary>
        /// 当前分类名
        /// </summary>
        public string classNames { get; set;  }

        /// <summary>
        /// 排序的类型
        /// </summary>
        public List<string> sortTypes { get; set; }

        /// <summary>
        /// 当前选中的排序类型
        /// </summary>
        public int currSortType { get; set; }
        #endregion
        /// <summary>
        /// 加载事件
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {

            try
            {
                //获取传递进来的ID 参数

                var categoryId = Common.GetParams(new Uri(Navigation.Uri).Query, "categoryId");
                //{where: "{"catId":"3921"}", limit: 10, page: 1, order: "sort asc"}
                var request_obj = new
                {
                    where =  $@"{{""catId"" : ""{categoryId}"" }}" ,//new { catId = $"{categoryId}" } ,
                    limit = 10,
                    page = 1,
                    order = "sort asc"
                };
                var goodsCategory = await  _HttpClient.Action<CoreCmsGoodsCategoryDto>("根据查询条件获取分页数据", request_obj, false);
                if (goodsCategory.status)
                {
                    _goodsCategory = goodsCategory.data;
                    classNames = _goodsCategory.className;
                }

            }
            catch (Exception ex)
            {
                throw;
            }
            await base.OnInitializedAsync();
        }

        public Task Search()
        {
            return Task.CompletedTask;
        }

        public Task GoDetail(int goodsId)
        {
            //   await Shell.Current.GoToAsync($"/Home/Mall/Detail?goods={goodsId}");
            Navigation.NavigateTo($"/Home/Mall/Detail?goods={goodsId}");
            return Task.CompletedTask;

        }

        /// <summary>
        /// 展开排序的类型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public Task ExpandSort(int value)
        {
            currSortType = value;
            return Task.CompletedTask;
        }
    }
}
